<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%
    String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+path+ "/"; 
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>新增或修改代理商信息</title>
	<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="bootstrap-table/dist/bootstrap-table.css">
    <link rel="stylesheet" type="text/css" href="css/xcConfirm.css" />
	<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />
	<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
	<link rel="stylesheet" href="bootstrap-fileinput-master/css/fileinput.min.css">
    
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">
    
    <style type="text/css">
        #panel {
            position: absolute;
            background-color: white;
            max-height: 90%;
            overflow-y: auto;
            top: 10px;
            right: 10px;
            width: 280px;
        }
        .td1{
			float:left;
			width:50px;
			display: block; 
			valign:middle;
		}
		.td2{
			float:left;
			width:200px;
			display: block; 
			valign:middle;
		}
		.td3{
			float:left;
			width:660px;
			display: block; 
			valign:middle;
		}
    </style>
</head>
<body>
	<div class="x-body">
            <div   class="form-horizontal" role="form">
            <input id="id" name="id" type="hidden" value="${user.gId}">
       	   <div class="form-group">
			  <label for="firstname" class="col-sm-2 control-label">*代理商账号:</label>
			    <div class="col-sm-3">
				    <c:if test="${user.gAccount!=null}">
				      <input type="text" class="form-control" id="account" readonly="readonly" name="account" required="required" placeholder="请输入账号" value="${user.gAccount}"/>
			        </c:if>
			        <c:if test="${user.gAccount==null}">
				      <input type="text" class="form-control" id="account" name="account" required="required" placeholder="请输入账号"/>
			        </c:if>
			    </div>
			  </div>
			  
			  <div class="form-group">
			  <label for="firstname" class="col-sm-2 control-label">*密码:</label>
			    <div class="col-sm-3">
			      <c:if test="${user.gPassword!=null}">
			          <input type="password" class="form-control" readonly="readonly" id="password" name="password" required="required" value="${user.gPassword}"/>
			      </c:if>
			      <c:if test="${user.gPassword==null}">
			          <input type="password" class="form-control" readonly="readonly" id="password" name="password" required="required" value="123456"/>
			      </c:if>
			    </div>
			  </div>
			  
			  
			  <div class="form-group">
			  <label for="firstname" class="col-sm-2 control-label">*代理级别:</label>
			    <div class="col-sm-3">
			      <input type="text" class="form-control" id="grade" name="grade" required="required" placeholder="请输入代理级别" value="${user.gGrade}"/>
			    </div>
			  </div>
			  
			  
			  <div class="form-group">
			  <label for="firstname" class="col-sm-2 control-label">*分成比例（%）:</label>
			    <div class="col-sm-3">
			      <input type="text" class="form-control" id="proportion" name="proportion" required="required" placeholder="请输入分成比例" value="${user.gProportion}"/>
			    </div>
			  </div>
			  
			  <div class="form-group">
			  <label for="firstname" class="col-sm-2 control-label">*推广二维码:</label>
			    <div class="col-sm-3">
			    <c:if test="${user.gId==null}">
				      <button type="submit" id="btn"  onclick="create()"  class="btn btn-info" >生成二维码</button>
			    </c:if> 
   		         <div class="QR">
				      <div id="qrcode">
				      </div>
				 </div>  
			    </div>
			  </div>
			  
			  <div class="form-group">
			  <label for="firstname" class="col-sm-2 control-label">*推广链接:</label>
			    <div class="col-sm-3">
			      <c:if test="${user.gId!=null}">
			         <input type="text" class="form-control" id="link" name="link" readonly="readonly" required="required" placeholder="请输入代理商级别" style="width:600px" value="http://www.shituzx.com/shareRegister?uId=${user.gId}"/>
			      </c:if>
			      <c:if test="${user.gId==null}">
			         <input type="text" class="form-control" id="link" name="link" readonly="readonly" required="required" placeholder="请输入代理商级别" value=""/>
			      </c:if>
			    </div>
			  </div>
			  
			  <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">备注:</label>
			    <div class="col-sm-3">
				    <c:if test="${user.gId!=null}">
				      <input type="text" class="form-control" id="remake" name="remake" required="required" placeholder="请输入代理商备注" value="${user.gRemake}" style="width:600px"/>
				    </c:if>
				    <c:if test="${user.gId==null}">
				      <input type="text" class="form-control" id="remake" name="remake" required="required" placeholder="请输入代理商备注"/>
				    </c:if>
			    </div>
			  </div>
			  
			  <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">启用状态:</label>
			    <div class="col-sm-3">
			      <select id="status" class="form-control">
             		<option value="1" <c:if test="${user.gStatus==1}">selected="selected"</c:if>>正常</option>
             		<option value="2" <c:if test="${user.gStatus==2}">selected="selected"</c:if>>停用</option>
              	  </select>
			    </div>
			  </div>
            
     	<div class="form-group" style="padding-left: 30%">
        
        <button type="submit"   onclick="save()"  class="btn btn-info" >保存</button>
        <!-- <button type="reset"    onclick="cancel()"  class="btn btn-info" >取消 </button> -->
   
     </div>
          </div>
	</div>
        <script src="lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="js/x-layui.js" charset="utf-8">
        </script>
        <!-- 加载需要的js -->
		<script src="js/jquery-3.2.1.min.js"></script>
		<script src="js/common2.js"></script>
		<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
		<script src="js/jquery-bootstrap-pagination.js"></script>
		<script src="js/qunit-1.11.0.js"></script>
		<script src="js/bootstrap-datetimepicker.js"></script>
		<script src="js/bootstrap-datetimepicker.zh-CN.js"></script>
	    <script src="js/xcConfirm.js" type="text/javascript" charset="utf-8"></script>
	    <script src="bootstrap-fileinput-master/js/fileinput.min.js"></script>
		<script src="bootstrap-fileinput-master/js/locales/zh.js"></script>
		<script src="js/jquery.qrcode.js"></script>
        <script>
            layui.use(['form','layer','upload'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer;
              });
            
          //时间插件
    		$('.form_date').datetimepicker({
    	        language:  'zh-CN',
    	        weekStart: 1,
    	        todayBtn:  1,
    			autoclose: 1,
    			todayHighlight: 1,
    			startView: 2,
    			minView: 2,
    			forceParse: 0
    	    });
    		
          
	   	   	$(function(){
	   	   	     var gId = $("#id").val();
	   	   		 if(gId!=0){
	   	   		      qrcode();
	   	   		 }
	   	   	});
          
            function save(){
	    	     var gId = $("#id").val();
	   		     var gAccount = $("#account").val();
	   			 if(gAccount == null||gAccount=="") {
	   				layer.msg('账号不能为空!',{icon:2,time:2000});
					  return ;
	   		   	 } 
	   			 var gPassword = $("#password").val();
	   		     var gGrade = $("#grade").val();
	   		     var gProportion = $("#proportion").val();
			 	 var gStatus = $("#status").find("option:selected").val();
			 	 if(gStatus == null||gStatus==" ") {
					layer.msg('状态不能为空!',{icon:2,time:2000});
					  return ;
			   	 }
			 	 var gRemake = $("#remake").val();
	   			 var  data = {"gId":gId,"gGrade":gGrade,"gAccount":gAccount,"gPassword":gPassword,"gProportion":gProportion,
	   		          	 "gStatus":gStatus,"gRemake":gRemake}
	   	         
	   	         $.ajax({
	   	             type: "post",
	   	             url: "sysUser/insertOrUpdate",
	   	             data: JSON.stringify(data),
	   	             contentType:"application/json;charset=UTF-8", 
	   	             dataType:"json",
	   	             success: function(data){    
		   	           	  if(data.code==200){
		   	           	      layer.alert(data.msg, {icon: 6},function () {
			   	           		  parent.location.reload();
			                      // 获得frame索引
			                      var index = parent.layer.getFrameIndex(window.name);
			                      //关闭当前frame
			                      parent.layer.close(index);
			                      parent.location.reload();
			                  });
				          }else{
				    	      var txt=data.msg;
				      	    	   layer.alert(txt); 
				      	  }
                    }
   	         });  
   	         
   			}
            
            
            function create(){
	   		     var gAccount = $("#account").val();
	   			 if(gAccount == null||gAccount=="") {
	   				layer.msg('账号不能为空!',{icon:2,time:2000});
					  return ;
	   		   	 } 
	   			 var gPassword = $("#password").val();
	   		     var gGrade = $("#grade").val();
	   		     var gProportion = $("#proportion").val();
			 	 var gStatus = $("#status").find("option:selected").val();
			 	 if(gStatus == null||gStatus==" ") {
					layer.msg('状态不能为空!',{icon:2,time:2000});
					  return ;
			   	 }
			 	 var gRemake = $("#remake").val();
	   			 var  data = {"gGrade":gGrade,"gAccount":gAccount,"gPassword":gPassword,"gProportion":gProportion,
	   		          	 "gStatus":gStatus,"gRemake":gRemake}
	   	         
	   	         $.ajax({
	   	             type: "post",
	   	             url: "sysUser/insertOrUpdate",
	   	             data: JSON.stringify(data),
	   	             contentType:"application/json;charset=UTF-8", 
	   	             dataType:"json",
	   	             success: function(data){    
		   	           	  if(data.code==200){
		   	                  $("#account").attr("readOnly","true");
		   	           		  $("#id").val(data.data);
		   	           		  $("#link").val("http://www.shituzx.com/shareRegister?uId="+data.data);
		   	           		  $("#btn").attr("style","display:none;");  
		   	           		  $("#QR").attr("style","display:block;");  
		   	           		  $("#qrcode").attr("style","display:block;");
		   	           	      qrcode();
				          }else{
				      	      layer.alert("生成失败，改账号已被添加，请重新输入账号"); 
				      	  }
                   }
  	         });  
  	         
  			}
   	   
   	   function cancel(){
   		   	
   		// 获得frame索引
           var index = parent.layer.getFrameIndex(window.name);
           //关闭当前frame
           parent.layer.close(index);
   	         
   			}
    	   
    	function qrcode(){
    		var gId = $("#id").val();
    		$("#qrcode").qrcode({  
    	        render : "canvas",    //设置渲染方式，有table和canvas，使用canvas方式渲染性能相对来说比较好  
    	        text : "http://www.shituzx.com/shareRegister?uId="+gId,    //扫描二维码后显示的内容,可以直接填一个网址，扫描二维码后自动跳向该链接  
    	        width : "200",               //二维码的宽度  
    	        height : "200",              //二维码的高度  
    	        background : "#ffffff",       //二维码的后景色  
    	        foreground : "#000000",        //二维码的前景色  
    	
    	    });  
    	}
        </script>
</body>
</html>